<?php

namespace App\Http\Controllers\Api\v1;

use App\Handlers\KeysHandler;
use App\Models\PaymentThirdPay;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Http\Resources\PaymentThirdPayResource;
use Illuminate\Support\Facades\Cache;

class PaymentThirdPayController extends Controller
{
    /**
     *
     * 支付方式
     * @return JsonResponse|object
     */
    public function index()
    {
        $payment = Cache::rememberForever(sprintf(KeysHandler::PAYMENT_THIRD_PAY_LIST), function () {
            return PaymentThirdPay::query()->open()->pay(PaymentThirdPay::PAY_OPEN)
                ->whereHas ('payment_third_code',function($query){
                    $query->open();
                })
                ->with(['payment_third_code'=>function($query){
                    $query->select('id','payment_third_pay_id','title','upper','lower')->open()->orderBy('sort','asc');
                }])
                ->select(['id','title'])
                ->orderBy('sort','asc')
                ->get();
        });
        return $this->success(PaymentThirdPayResource::collection($payment));


    }



}
